package com.icard.wx.icardwx.controller;


import com.dsbj.common.model.Dept;
import com.dsbj.common.model.Reservation;
import com.dsbj.common.model.ReservationPrimary;
import com.dsbj.common.msg.ResponseMessage;
import com.icard.wx.icardwx.model.AllowUser;
import com.icard.wx.icardwx.model.WxUser;
import com.icard.wx.icardwx.service.IDeptService;
import com.icard.wx.icardwx.service.IReservationService;
import com.icard.wx.icardwx.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/dept")
public class DeptController extends BaseController{

    @Autowired
    private IDeptService deptService;

    @RequestMapping("/searchDeptByKeyword")
    @ResponseBody
    public List<Dept> searchDeptByKeyword(Model model, HttpServletRequest request, HttpServletResponse response,String keywords){

        WxUser user = (WxUser) request.getSession().getAttribute(Constants.SESSION_USER);
        if(user==null){
            return new ArrayList<>();
        }

        List<Dept> dataList = new ArrayList<>();
        ResponseMessage<List<Dept>> rsp =  deptService.searchDeptByKeyword(keywords,user.getCompanyno());

        if(rsp!=null&&!CollectionUtils.isEmpty(rsp.getData())){
            dataList = rsp.getData();
        }
        return dataList;
    }

}
